package com.zzyl.mapper;

import com.zzyl.dto.ResourceDto;
import com.zzyl.entity.Resource;
import com.zzyl.vo.MenuVo;
import org.apache.ibatis.annotations.*;

import java.util.List;


@Mapper
public interface ResourceMapper {


    int deleteByPrimaryKey(Long id);

    int insert(Resource record);

    int insertSelective(Resource record);


    Resource selectByPrimaryKey(Long id);



    int updateByPrimaryKeySelective(Resource record);

    int updateByPrimaryKey(Resource record);

    /**
     * 这是Mybatis Generator拓展插件生成的方法(请勿删除).
     * This method corresponds to the database table sys_resource
     *
     * @mbg.generated
     * @author hewei
     */
    int batchInsert(@Param("list") List<Resource> list);


    /**
     * 多条件查询资源列表
     * @param
     * @return
     */
    List<Resource> selectList(ResourceDto resourceDto);


    /**
     * 添加
     * @param parentResourceNo
     * @return
     */
    @Select("select * from sys_resource where resource_no = #{resourceNo}")
    Resource selectByResourceNo(String parentResourceNo);






    /**
     * 根据资源编号修改
     * @param resourceNo
     * @param dataState
     */

@Update("update sys_resource set data_state=#{dataState} where resource_no=#{resourceNo}")
    void updateByResourceNo(@Param("resourceNo") String resourceNo,@Param("dataState") String dataState);


    /**
     * 根据父类资源编号修改
     * @param s
     * @param dataState
     */
    @Update("update sys_resource set data_state=#{dataState} where resource_no=#{parentResourceNo}")
    void updateByParentResourceNo(@Param("parentResourceNo") String s, @Param("dataState")String dataState);


    /**
     * 计算是否有子菜单
     * @param resourceNo
     * @return
     */
@Select("select count(1) from sys_resource where parent_resource_no=#{resourceNo}")
    int countExistSubmenu(String resourceNo);


    /**
     * 删除
     * @param resourceNo
     */
    @Delete("delete from sys_resource where resource_no=#{resourceNo}")
    void deleteByResourceNo(String resourceNo);


    /**
     * 根据userId查资源
     * @param id
     * @return
     */
    List<Resource> selectListByUserId(Long id);


    /**
     * 左侧菜单
     * @param userId
     * @return
     */
    List<MenuVo> findListByUserId(Long userId);
}